import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.store({
	state: {
		count: 0
	},
	mutations: {
		add(state) {
			//setTimeout(() => {
				state.count++
			//},1000)
		},
		addN(state, step) {
			state.count += step
		},
	    sub(state) {
			state.count--
		},
		subN(state, step) {
			state.count -= step
		}
		
	},
	action: {
		addAsync(context) {
			setTimeout(() => {
			  context.commit('add')
			},1000)
		},
		addNAsync(context,step) {
			setTimeout(() => {
			  context.commit('addN',step)
			},1000)
		},
		subAsync(context) {
			setTimeout(() => {
				context.commit('sub')
			},1000)
		},
		subNAsync(context, step) {
			setTimeout(() => {
			  context.commit('subN',step)
			},1000)
		}
	},
	getters: {
		showNum(state) {
			return '当前数量是【' + state.count + '】'
			}
	}
})